import type { UploadRequestOptions } from 'element-plus'
import type { UserDesktopBg, UserInfo, UserLogin, UserUpdatePwd } from '../types'
import type {
  RequestPaginationResultData,
  RequestParams,
  RequestResultData
} from 'hippo-module-core'
import bgImg from '../assets/img/desktop-layout/light-bg.jpg'
import bgPreviewImg from '../assets/img/desktop-layout/light-bg-preview.jpg'
import { ThemeStoreUtil, ThemeUtil } from '../utils'

export default class UserApi {
  /**
   * 获取用户桌面背景预览
   * @returns
   */
  static getUserDesktopBgPreview() {
    return new Promise<RequestResultData<UserDesktopBg>>((resolve) => {
      //本地获取，可修改成后端获取
      const bg = window.localStorage.getItem('bg') || bgPreviewImg
      resolve({
        status: 200,
        success: true,
        msg: '获取用户桌面背景预览图成功！',
        data: {
          bgUrl: bg
        }
      })
    })
  }

  /**
   * 获取用户桌面背景
   * @returns
   */
  static getUserDesktopBg() {
    return new Promise<RequestResultData<UserDesktopBg>>((resolve) => {
      //本地获取，可修改成后端获取
      const bg = window.localStorage.getItem('bg') || bgImg
      resolve({
        status: 200,
        success: true,
        msg: '获取用户桌面背景成功！',
        data: {
          bgUrl: bg
        }
      })
    })
  }

  /**
   * 上传用户桌面背景
   * @param options
   * @returns
   */
  static userDesktopBgUpload(options: UploadRequestOptions) {
    return new Promise<RequestResultData<UserDesktopBg>>((resolve) => {
      //本地保存，后面可修改成上传到后端
      const reader = new FileReader()
      reader.onload = (e) => {
        if (e.target && e.target.result) {
          window.localStorage.setItem('bg', e.target.result.toString())
          resolve({
            status: 200,
            success: true,
            msg: '上传成功！',
            data: {
              bgUrl: e.target.result.toString()
            }
          })
        }
      }

      reader.readAsDataURL(options.file)

      /**
       *  上传到后端使用
       *  const formData = new FormData()
       *  formData.append('file', options.file)
       */
    })
  }

  /**
   * 验证码
   * @returns
   */
  static getValidateCode() {
    return ''
  }

  /**
   * 登录
   * @returns
   */
  static login() {
    return new Promise<RequestResultData<UserLogin>>((resolve) => {
      const data: RequestResultData<UserLogin> = {
        status: 200,
        success: true,
        msg: '',
        data: {
          token: 'fsfaKLKufdsf4545faa11fsfasfdfsf',
          userInfo: {
            id: 'dasfsdfasd232434',
            userName: 'admin',
            realName: '伊丽莎白.买买提',
            avatar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
            sex: '1',
            tel: '18985458699',
            email: '18985458699@qq.com'
          },
          routers: [
            {
              path: '/',
              name: 'DesktopLayout',
              component: 'DesktopLayout',
              isLayout: true,
              meta: {
                title: 'DesktopLayout'
              },
              children: [
                {
                  isLayout: false,
                  path: '/UserList',
                  name: 'UserList',
                  component: 'user/UserList.vue',
                  meta: {
                    title: '用户管理',
                    icon: 'SvgIconUser'
                  }
                },
                {
                  isLayout: false,
                  path: '/UserInfo',
                  name: 'UserInfo',
                  component: 'user/UserInfo.vue',
                  meta: {
                    title: '用户信息',
                    icon: 'SvgIconUser'
                  }
                },
                {
                  isLayout: false,
                  path: '/RoleList',
                  name: 'RoleList',
                  component: 'role/RoleList.vue',
                  meta: {
                    title: '角色管理',
                    icon: 'SvgIconRole'
                  }
                },
                {
                  isLayout: false,
                  path: '/Home',
                  name: 'Home',
                  component: 'home/Home.vue',
                  meta: {
                    title: '首页',
                    icon: 'SvgIconHome'
                  }
                },
                {
                  isLayout: false,
                  path: '/EchartDemo',
                  name: 'EchartDemo',
                  component: 'echart-demo/Demo.vue',
                  meta: {
                    title: 'demo',
                    icon: 'SvgIconDemo'
                  }
                },
                {
                  isLayout: false,
                  path: '/TopoDemo',
                  name: 'TopoDemo',
                  component: 'topo-demo/TopoDemo.vue',
                  meta: {
                    title: '拓扑图',
                    icon: 'SvgIconDemo'
                  }
                },
                {
                  isLayout: false,
                  path: '/MenuList',
                  name: 'MenuList',
                  component: 'menu/MenuList.vue',
                  meta: {
                    title: '菜单管理',
                    icon: 'SvgIconMenu'
                  }
                },
                {
                  isLayout: false,
                  path: '/MsgList',
                  name: 'MsgList',
                  component: 'msg/MsgList.vue',
                  meta: {
                    title: '消息管理',
                    icon: 'SvgIconNotice'
                  }
                },
                {
                  isLayout: false,
                  path: '/MsgInfo/:id',
                  name: 'MsgInfo',
                  component: 'msg/MsgInfo.vue',
                  meta: {
                    title: '消息信息',
                    icon: 'SvgIconNotice'
                  }
                },
                {
                  isLayout: false,
                  path: '/LogList',
                  name: 'LogList',
                  component: 'log/LogList.vue',
                  meta: {
                    title: '日志管理',
                    icon: 'SvgIconLog'
                  }
                },
                {
                  isLayout: false,
                  path: '/DataDicList',
                  name: 'DataDicList',
                  component: 'data-dic/DataDicList.vue',
                  meta: {
                    title: '数据字典管理',
                    icon: 'SvgIconDataDic'
                  }
                },
                {
                  isLayout: false,
                  path: '/AuthList',
                  name: 'AuthList',
                  component: 'auth/AuthList.vue',
                  meta: {
                    title: '权限管理',
                    icon: 'SvgIconAuth'
                  }
                },
                {
                  isLayout: false,
                  path: '/WorkFlowList',
                  name: 'WorkFlowList',
                  component: 'work-flow/WorkFlowList.vue',
                  meta: {
                    title: '流程管理',
                    icon: 'SvgIconFlow'
                  }
                },
                {
                  isLayout: false,
                  path: '/WorkFlowAdd',
                  name: 'WorkFlowAdd',
                  component: 'work-flow/WorkFlowAdd.vue',
                  meta: {
                    title: '新增流程',
                    icon: 'SvgIconFlow'
                  }
                },
                {
                  isLayout: false,
                  path: '/WorkFlowEdit/:id',
                  name: 'WorkFlowEdit',
                  component: 'work-flow/WorkFlowEdit.vue',
                  meta: {
                    title: '编辑流程',
                    icon: 'SvgIconFlow'
                  }
                },
                {
                  isLayout: false,
                  path: '/BabylonSphereDemo',
                  name: 'BabylonSphereDemo',
                  component: 'babylon-demo/BabylonSphereDemo.vue',
                  meta: {
                    title: 'BabylonSphereDemo',
                    icon: 'SvgIconDemo'
                  }
                },
                {
                  isLayout: false,
                  path: '/LoadingDemo',
                  name: 'LoadingDemo',
                  component: 'loading-demo/LoadingDemo.vue',
                  meta: {
                    title: 'LoadingDemo',
                    icon: 'SvgIconDemo'
                  }
                },
                {
                  isLayout: false,
                  path: '/PreviewDemo',
                  name: 'PreviewDemo',
                  component: 'preview-demo/PreviewDemo.vue',
                  meta: {
                    title: '预览',
                    icon: 'SvgIconDemo'
                  }
                },
                {
                  isLayout: false,
                  path: '/AwesomeQrDemo',
                  name: 'AwesomeQrDemo',
                  component: 'awesome-qr-demo/AwesomeQrDemo.vue',
                  meta: {
                    title: 'awesome-qr',
                    icon: 'SvgIconDemo'
                  }
                },
                {
                  isLayout: false,
                  path: '/CustomCompDemo',
                  name: 'CustomCompDemo',
                  component: 'custom-comp-demo/CustomCompDemo.vue',
                  meta: {
                    title: '自定义组件',
                    icon: 'SvgIconDemo'
                  }
                },
                {
                  isLayout: false,
                  path: '/ClipPathDemo',
                  name: 'ClipPathDemo',
                  component: 'clip-path-demo/ClipPathDemo.vue',
                  meta: {
                    title: 'clip-path',
                    icon: 'SvgIconDemo'
                  }
                },
                {
                  isLayout: false,
                  path: '/GuideDemo',
                  name: 'GuideDemo',
                  component: 'guide-demo/GuideDemo.vue',
                  meta: {
                    title: '引导页',
                    icon: 'SvgIconDemo'
                  }
                },
                {
                  isLayout: false,
                  path: '/WaterfallDemo',
                  name: 'WaterfallDemo',
                  component: 'waterfall-demo/WaterfallDemo.vue',
                  meta: {
                    title: '瀑布流',
                    icon: 'SvgIconDemo'
                  }
                },
                {
                  isLayout: false,
                  path: '/JiuGongDemo',
                  name: 'JiuGongDemo',
                  component: 'jiu-gong-demo/JiuGongDemo.vue',
                  meta: {
                    title: '九宫格图片',
                    icon: 'SvgIconDemo'
                  }
                },
                {
                  isLayout: false,
                  path: '/EditDemo',
                  name: 'EditDemo',
                  component: 'edit-demo/EditDemo.vue',
                  meta: {
                    title: '富文本编辑器',
                    icon: 'SvgIconDemo'
                  }
                },
                {
                  isLayout: false,
                  path: '/VideoPlayerDemo',
                  name: 'VideoPlayerDemo',
                  component: 'video-player-demo/VideoPlayerDemo.vue',
                  meta: {
                    title: '视频播放器',
                    icon: 'SvgIconDemo'
                  }
                },
                {
                  isLayout: false,
                  path: '/KnowledgeDemo',
                  name: 'KnowledgeDemo',
                  component: 'knowledge-demo/KnowledgeDemo.vue',
                  meta: {
                    title: '知识库',
                    icon: 'SvgIconDemo'
                  }
                },
                {
                  isLayout: false,
                  path: '/DataBoardDemo',
                  name: 'DataBoardDemo',
                  component: 'data-board-demo/DataBoardDemo.vue',
                  meta: {
                    title: '数据看板',
                    icon: 'SvgIconDemo'
                  }
                },
                {
                  isLayout: false,
                  path: '/ShellDemo',
                  name: 'ShellDemo',
                  component: 'shell-demo/ShellDemo.vue',
                  meta: {
                    title: '命令行',
                    icon: 'SvgIconDemo'
                  }
                },
                {
                  isLayout: false,
                  path: '/AtlasDemo',
                  name: 'AtlasDemo',
                  component: 'atlas-demo/AtlasDemo.vue',
                  meta: {
                    title: '知识图谱',
                    icon: 'SvgIconDemo'
                  }
                },
                {
                  isLayout: false,
                  path: '/D3Demo',
                  name: 'D3Demo',
                  component: 'd3-demo/D3Demo.vue',
                  meta: {
                    title: 'D3示例',
                    icon: 'SvgIconDemo'
                  }
                },
                {
                  isLayout: false,
                  path: '/VisDemo',
                  name: 'VisDemo',
                  component: 'vis-demo/VisDemo.vue',
                  meta: {
                    title: 'vis示例',
                    icon: 'SvgIconDemo'
                  }
                },
                {
                  isLayout: false,
                  path: '/FormCreateEditor',
                  name: 'FormCreateEditor',
                  component: 'form-create-editor/FormCreateEditor.vue',
                  meta: {
                    title: 'FormCreateEditor示例',
                    icon: 'SvgIconDemo'
                  }
                }
              ]
            }
          ],
          commonMenus: [
            {
              id: 'Home',
              icon: 'SvgIconHome',
              label: '首页',
              path: '/Home'
            },
            {
              id: 'NotFound',
              icon: 'SvgIconNotice',
              label: '消息管理',
              path: '/MsgList'
            },
            {
              id: 'logList',
              icon: 'SvgIconLog',
              label: '日志管理',
              path: '/LogList'
            },
            {
              id: 'UserList',
              icon: 'SvgIconUser',
              label: '用户管理',
              path: '/UserList'
            },
            {
              id: 'RoleList',
              icon: 'SvgIconRole',
              label: '角色管理',
              path: '/RoleList'
            },
            {
              id: 'WorkFlowList',
              icon: 'SvgIconFlow',
              label: '流程管理',
              path: '/WorkFlowList'
            },
            {
              id: 'echartDemo',
              icon: 'SvgIconDemo',
              label: 'echartDemo',
              path: '/EchartDemo'
            },
            {
              id: 'topoDemo',
              icon: 'SvgIconDemo',
              label: '拓扑图',
              path: '/TopoDemo'
            },
            {
              id: 'babylonSphereDemo',
              icon: 'SvgIconDemo',
              label: 'babylonSphereDemo',
              path: '/BabylonSphereDemo'
            },
            {
              id: 'loadingDemo',
              icon: 'SvgIconDemo',
              label: '加载动画',
              path: '/LoadingDemo'
            },
            {
              id: 'previewDemo',
              icon: 'SvgIconDemo',
              label: '预览',
              path: '/PreviewDemo'
            },
            {
              id: 'awesomeQrDemo',
              icon: 'SvgIconDemo',
              label: 'awesome-qr',
              path: '/AwesomeQrDemo'
            },
            {
              id: 'customCompDemo',
              icon: 'SvgIconDemo',
              label: '自定义组件',
              path: '/CustomCompDemo'
            },
            {
              id: 'clipPathDemo',
              icon: 'SvgIconDemo',
              label: 'clip-path',
              path: '/ClipPathDemo'
            },
            {
              id: 'guideDemo',
              icon: 'SvgIconDemo',
              label: '引导页',
              path: '/GuideDemo'
            },
            {
              id: 'waterfallDemo',
              icon: 'SvgIconDemo',
              label: '瀑布流',
              path: '/WaterfallDemo'
            },
            {
              id: 'jiuGongDemo',
              icon: 'SvgIconDemo',
              label: '九宫格图片',
              path: '/JiuGongDemo'
            },
            {
              id: 'editDemo',
              icon: 'SvgIconDemo',
              label: '富文本编辑器',
              path: '/EditDemo'
            },
            {
              id: 'videoPlayerDemo',
              icon: 'SvgIconDemo',
              label: '视频播放器',
              path: '/VideoPlayerDemo'
            },
            {
              id: 'knowledgeDemo',
              icon: 'SvgIconDemo',
              label: '知识库',
              path: '/KnowledgeDemo'
            },
            {
              id: 'dataBoardDemo',
              icon: 'SvgIconDemo',
              label: '数据看板',
              path: '/DataBoardDemo'
            },
            {
              id: 'shellDemo',
              icon: 'SvgIconDemo',
              label: '命令行',
              path: '/ShellDemo'
            },
            {
              id: 'atlasDemo',
              icon: 'SvgIconDemo',
              label: '知识图谱',
              path: '/AtlasDemo'
            },
            {
              id: 'd3Demo',
              icon: 'SvgIconDemo',
              label: 'D3示例',
              path: '/D3Demo'
            },
            {
              id: 'visDemo',
              icon: 'SvgIconDemo',
              label: 'vis示例',
              path: '/VisDemo'
            },
            {
              id: 'formCreateEditor',
              icon: 'SvgIconDemo',
              label: 'FormCreateEditor示例',
              path: '/FormCreateEditor'
            }
          ],
          menus: [
            {
              id: 'Home',
              icon: 'SvgIconHome',
              label: '首页',
              path: '/Home'
            },
            {
              id: 'UserList',
              icon: 'SvgIconUser',
              label: '用户管理',
              path: '/UserList'
            },
            {
              id: 'RoleList',
              icon: 'SvgIconRole',
              label: '角色管理',
              path: '/RoleList'
            },
            {
              id: 'MenuList',
              icon: 'SvgIconMenu',
              label: '菜单管理',
              path: '/MenuList'
            },
            {
              id: 'UserInfo',
              icon: 'SvgIconDataDic',
              label: '数据字典管理',
              path: '/DataDicList'
            },
            {
              id: 'MsgList',
              icon: 'SvgIconNotice',
              label: '消息管理',
              path: '/MsgList'
            },
            {
              id: 'WorkFlowList',
              icon: 'SvgIconFlow',
              label: '流程管理',
              path: '/WorkFlowList'
            },
            {
              id: 'logList',
              icon: 'SvgIconLog',
              label: '日志管理',
              path: '/LogList'
            },
            {
              id: 'authList',
              icon: 'SvgIconAuth',
              label: '权限管理',
              path: '/AuthList'
            },
            {
              id: 'echartDemo',
              icon: 'SvgIconDemo',
              label: 'echartDemo',
              path: '/EchartDemo'
            },
            {
              id: 'topoDemo',
              icon: 'SvgIconDemo',
              label: '拓扑图',
              path: '/TopoDemo'
            },
            {
              id: 'babylonSphereDemo',
              icon: 'SvgIconLog',
              label: 'babylonSphereDemo',
              path: '/BabylonSphereDemo'
            },
            {
              id: 'loadingDemo',
              icon: 'SvgIconDemo',
              label: '加载动画',
              path: '/LoadingDemo'
            },
            {
              id: 'previewDemo',
              icon: 'SvgIconDemo',
              label: '预览',
              path: '/PreviewDemo'
            },
            {
              id: 'awesomeQrDemo',
              icon: 'SvgIconDemo',
              label: 'awesome-qr',
              path: '/AwesomeQrDemo'
            },
            {
              id: 'customCompDemo',
              icon: 'SvgIconDemo',
              label: '自定义组件',
              path: '/CustomCompDemo'
            },
            {
              id: 'clipPathDemo',
              icon: 'SvgIconDemo',
              label: 'clip-path',
              path: '/ClipPathDemo'
            },
            {
              id: 'guideDemo',
              icon: 'SvgIconDemo',
              label: '引导页',
              path: '/GuideDemo'
            },
            {
              id: 'waterfallDemo',
              icon: 'SvgIconDemo',
              label: '瀑布流',
              path: '/WaterfallDemo'
            },
            {
              id: 'jiuGongDemo',
              icon: 'SvgIconDemo',
              label: '九宫格图片',
              path: '/JiuGongDemo'
            },
            {
              id: 'editDemo',
              icon: 'SvgIconDemo',
              label: '富文本编辑器',
              path: '/EditDemo'
            },
            {
              id: 'videoPlayerDemo',
              icon: 'SvgIconDemo',
              label: '视频播放器',
              path: '/VideoPlayerDemo'
            },
            {
              id: 'knowledgeDemo',
              icon: 'SvgIconDemo',
              label: '知识库',
              path: '/KnowledgeDemo'
            },
            {
              id: 'dataBoardDemo',
              icon: 'SvgIconDemo',
              label: '数据看板',
              path: '/DataBoardDemo'
            },
            {
              id: 'shellDemo',
              icon: 'SvgIconDemo',
              label: '命令行',
              path: '/ShellDemo'
            },
            {
              id: 'atlasDemo',
              icon: 'SvgIconDemo',
              label: '知识图谱',
              path: '/AtlasDemo'
            },
            {
              id: 'd3Demo',
              icon: 'SvgIconDemo',
              label: 'D3示例',
              path: '/D3Demo'
            },
            {
              id: 'visDemo',
              icon: 'SvgIconDemo',
              label: 'vis示例',
              path: '/VisDemo'
            }
          ]
        }
      }
      resolve(data)
    })
  }

  /**
   * 更新当前用户密码
   * @param params
   * @returns
   */
  static updateCurrentUserPwd(params: UserUpdatePwd) {
    return new Promise<RequestResultData<Object>>((resolve) => {
      resolve({
        status: 200,
        success: true,
        msg: '',
        data: {}
      })
    })
  }

  /**
   * 更新当前用户信息
   * @param params
   * @returns
   */
  static updateCurrentUserInfo(params: UserInfo) {
    return new Promise<RequestResultData<Object>>((resolve) => {
      resolve({
        status: 200,
        success: true,
        msg: '',
        data: {}
      })
    })
  }

  static getUserListByParams(params: RequestParams) {
    return new Promise<RequestPaginationResultData<UserInfo[]>>((resolve) => {
      resolve({
        status: 200,
        success: true,
        msg: '',
        data: {
          total: 100,
          list: [
            {
              id: 'dasfsdfasd232434',
              userName: 'admin',
              realName: '伊丽莎白.买买提',
              avatar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
              sex: '1',
              tel: '18985458699',
              email: '18985458699@qq.com',
              createUser: 'admin',
              createDate: '2023-07-11 15:35:45'
            }
          ]
        }
      })
    })
  }

  static deleteUserByIds(ids: string[]) {
    return new Promise<RequestResultData<Object>>((resolve) => {
      resolve({
        status: 200,
        success: true,
        msg: '',
        data: {}
      })
    })
  }
}
